#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    int totalMoney(int n)
    {
        int week = 1, day = 1;
        int res = 0;
        for (int i = 0; i < n; ++i)
        {
            res += week + day - 1;
            ++day;
            if (day == 8)
            {
                day = 1;
                ++week;
            }
        }
        return res;
    }
    int totalMoney_1(int n)
    { // 所有完整的周存的钱
        int weekNumber = n / 7;
        int firstWeekMoney = (1 + 7) * 7 / 2;
        int lastWeekMoney = firstWeekMoney + 7 * (weekNumber - 1);
        int weekMoney = (firstWeekMoney + lastWeekMoney) * weekNumber / 2;
        // 剩下的不能构成一个完整的周的天数里存的钱
        int dayNumber = n % 7;
        int firstDayMoney = 1 + weekNumber;
        int lastDayMoney = firstDayMoney + dayNumber - 1;
        int dayMoney = (firstDayMoney + lastDayMoney) * dayNumber / 2;
        return weekMoney + dayMoney;
    }

    int totalMoney_2(int n)
    {
        int weeks = n / 7;
        //  先求出整星期数存的钱，整星期数存的钱是一个首项为28，公差为7的等差数列
        int weekMoney = 28 * weeks + weeks * (weeks - 1) / 2 * 7;
        int lastWeekDays = n % 7;
        //  再用整星期数存的钱加上剩余的天数存的钱，剩余的天数存的钱是一个首项为m+1，公差为1的等差数列
        return weekMoney + lastWeekDays * (weeks + 1) + lastWeekDays * (lastWeekDays - 1) / 2;
    }
};
int main()
{
    Solution s;
    int n = 4;
    cout << s.totalMoney(n) << endl;
    system("pause");
    return 0;
}
